package xc.src.生产者消费者案例01;

public class Box {
    private boolean state=false;

    private int milk;

    public synchronized void put(int milk){
        if (state){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.milk=milk;
        System.out.println("送奶工将第"+milk+"瓶牛奶放入箱中");

        state=true;

        notifyAll();
    }
       public synchronized  void get() {
           if (!state) {
               try {
                   wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
           System.out.println("用户拿到第" + milk + "瓶牛奶");

           state = false;
           notifyAll();
       }
    }

